package com.graduation.books_borrow.Service.impl;

import com.graduation.books_borrow.Service.BooksQueryService;
import com.graduation.books_borrow.entity.Book;
import com.graduation.books_borrow.repository.BooksQueryMapper;
import com.graduation.books_borrow.ret.R;
import com.graduation.books_borrow.ret.Rcode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BooksQueryServiceImpl implements BooksQueryService {

    @Autowired
    private BooksQueryMapper booksQueryMapper;

    @Override
    public R booksQuery(Book book) {

        List<Book> book2 = null;

        if ((book.getBookName() == null || "".equals(book.getBookName()))
                && (book.getAuthor() == null || "".equals(book.getAuthor()))) {
            book2  = booksQueryMapper.booksQuery();
        } else if ((!"".equals(book.getBookName()))
                && (book.getAuthor() == null || "".equals(book.getAuthor()))) {
            book2 = booksQueryMapper.booksQueryByName(book);
        } else if ((book.getBookName() == null || "".equals(book.getBookName()))
                && (!"".equals(book.getAuthor()))) {
            book2 = booksQueryMapper.booksQueryByAuthor(book);
        } else {
            book2 = booksQueryMapper.booksQueryByNameAuthor(book);
        }

        return R.ret(Rcode.QUERY_BOOKS_SUCCESS, Rcode.QUERY_BOOKS_SUCCESS_DESC, book2);
    }
}
